<template>
  <div>
    <h1>新增名片</h1>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="姓名">
        <el-col :span="11">
          <el-input v-model="form.name"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="选择生日">
        <el-col :span="11">
          <el-date-picker type="date" placeholder="选择日期" v-model="form.birthday" style="width: 100%;"></el-date-picker>
        </el-col>
      </el-form-item>

      <el-form-item label="性别">
        <el-radio-group v-model="form.sex">
          <el-radio label="男"></el-radio>
          <el-radio label="女"></el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="公司">
        <el-col :span="11">
          <el-input v-model="form.company"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="职位">
        <el-col :span="11">
          <el-input v-model="form.position"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item label="手机">
        <el-col :span="11">
          <el-input v-model="form.mobile"></el-input>
        </el-col>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSubmit">新增名片</el-button>
        <el-button>取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: 'CardAdd',
  data() {
    return {
      msg: '新增卡片',
      form: {
        name: '',
        birthday: '',
        sex: '',
        company: '',
        position: '',
        mobile: ''
      }
    }
  },
  methods: {
    onSubmit() {
      let vm = this;
      this.axios({
        url: 'http://localhost:8080/card/add',
        method: 'POST',
        data: vm.form
      }).then(function (res) {
        if (res.data.code == 0) {
          vm.$message.success('名片添加成功!');
          setTimeout(function () {
            vm.$router.push('cardList');
          }, 1000);
        }
      });
    }
  }
}
</script>

<style scoped>
</style>
